import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  { /* 首页页面 */
    path: '/HomeView',
    name: 'HomeView',
    component: () => import('@/views/HomeView'),
    children: [
      { /* 个人信息页面 */
        path: '/PersonInfo',
        name: 'PersonInfo',
        component: () => import('@/views/PersonInfo')
      },
      { /* 修改密码页面 */
        path: '/UpdatePasswordView',
        name: 'UpdatePasswordView',
        component: () => import('@/views/UpdatePasswordView')
      },
      { /* 后台用户页面 */
        path: '/UserView',
        name: 'UserView',
        component: () => import('@/views/BackManage/UserView')
      },
      { /* 后台角色页面 */
        path: '/RoleView',
        name: 'RoleView',
        component: () => import('@/views/BackManage/RoleView')
      },
      { /* 后台菜单页面 */
        path: '/MenuView',
        name: 'MenuView',
        component: () => import('@/views/BackManage/MenuView')
      },
      // 用户购买会员记录 gpd 2022-10-12 10点43分
      {
        path: '/memberRecord',
        name: 'MemberRecord',
        component: () => import('@/views/MemberManage/MemberRecord')
      },
      // 会员类型 gpd 2022-10-12 11点25分
      {
        path: '/memberType',
        name: 'MemberType',
        component: () => import('@/views/MemberManage/MemberType')
      },
      // 会员价格管理 gpd 2022-10- 12 14点45分
      {
        path: '/memberPrice',
        name: 'MemberPrice',
        component: () => import('@/views/MemberManage/MemberPrice')
      },
      // 骑手审批管理 hbx 2022年10月14日10:59:17
      {
        path: '/auditView',
        name: 'AuditView',
        component: () => import('@/views/ExamineManage/AuditView')
      },
      // 商家审批管理 cjl 2022年10月18日10:27:42
      {
        path: '/MerchantView',
        name: 'MerchantView',
        component: () => import('@/views/ExamineManage/MerchantView')
      },
      { /* 前台用户页面 */
        path: '/FrontUserView',
        name: 'FrontUserView',
        component: () => import('@/views/FrontDeskManage/FrontUserView')
      },
      { /* 前台商家页面 */
        path: '/FrontMerchantView',
        name: 'FrontMerchantView',
        component: () => import('@/views/FrontDeskManage/FrontMerchantView')
      },
      { /* 前台骑手页面 */
        path: '/FrontHorsemanView',
        name: 'FrontHorsemanView',
        component: () => import('@/views/FrontDeskManage/FrontHorsemanView')
      },
      { /* 前台店铺页面 */
        path: '/FrontShopView',
        name: 'FrontShopView',
        component: () => import('@/views/FrontDeskManage/FrontShopView')
      }
    ]
  },
  {
    path: '/',
    name: 'LoginView',
    component: () => import(/* webpackChunkName: "about" */ '@/views/LoginView')
  }
]

const router = new VueRouter({
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  if (to.path === '/') {
    next()
  } else {
    const token = window.sessionStorage.getItem('token')
    if (token) {
      next()
    } else {
      next('/')
    }
  }
})

export default router
